package ngames.com.sushitv.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;

import ngames.com.sushitv.R;
import ngames.com.sushitv.base.BaseListAdapter;
import ngames.com.sushitv.entity.ButtonHome;
import ngames.com.sushitv.entity.ItemVideo;

/**
 * Created by Fearless on 2016/6/26.
 */
public class FanMadeBtnAdapter extends BaseListAdapter<ButtonHome> {

    public FanMadeBtnAdapter(Context context, ArrayList<ButtonHome> list) {
        super(context, list);

    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new VideoRankHolder(mInflater.inflate(R.layout.item_fanmade_img_text, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        VideoRankHolder videoRankHolder = (VideoRankHolder) holder;
        videoRankHolder.setData(position);
    }


    class VideoRankHolder extends RecyclerView.ViewHolder {
        TextView nameTxt;
        ImageView imageView;

        public VideoRankHolder(View itemView) {
            super(itemView);
            nameTxt = (TextView) itemView.findViewById(R.id.text_item_fanmade);
            imageView = (ImageView) itemView.findViewById(R.id.img_item_fanmade);
        }

        public void setData(int position) {
            ButtonHome button = getItem(position);
            nameTxt.setText(button.getName());
            DisplayImageOptions options = new DisplayImageOptions.Builder()
                    /*.showStubImage(R.drawable.image_is_loading)            // 设置图片下载期间显示的图片
                    .showImageForEmptyUri(R.drawable.image_loading_failed)    // 设置图片Uri为空或是错误的时候显示的图片
                    .showImageOnFail(R.drawable.image_loading_failed)        // 设置图片加载或解码过程中发生错误显示的图片*/
                    .cacheInMemory(true)                        // 设置下载的图片是否缓存在内存中
                    .cacheOnDisc(true)                            // 设置下载的图片是否缓存在SD卡中
                    .build();
            String workerImgStr = button.getIcon();
            ImageLoader.getInstance().displayImage(workerImgStr, imageView, options);// 创建配置过得DisplayImageOption对象
        }
    }
}
